﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace System
{
    public class ZPager
    {
        public static DataTable TablePage(DataTable dt, int pageSize, int pageIndex)
        {
            DataTable newDt = new DataTable();
            newDt = dt.Clone();
            int pageMin = pageSize * (pageIndex - 1);
            int pageMax = pageSize * (pageIndex - 1) + pageSize;
            if (dt.Rows.Count >= pageMax)
            {
                for (int i = pageMin; i < pageMax; i++)
                {

                    newDt.ImportRow(dt.Rows[i]);
                }
            }
            else
            {
                for (int i = pageMin; i < dt.Rows.Count; i++)
                {

                    newDt.ImportRow(dt.Rows[i]);
                }
            }
            return newDt;
        }
    }
}
